'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-01-16 18:07:40
'''
import os
import sys
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir)))

import thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hulk_proxy.HulkProxyServ import Client
from scan_data.ttypes import ScanData

__HOST = "172.21.32.54"
__PORT = 10088

try:
    tsocket = TSocket.TSocket(__HOST, __PORT)
    transport = TTransport.TFramedTransport(tsocket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Client(protocol)

    transport.open()


    '''
    @note: write the cut_points
    '''
    f = open('./feature/cut_points.json', 'r')
    cut_points = json.load(f)
    f.close()

    cut_points = json.dumps(cut_points)
    # print(type(layer))
    client.hpush("feature_meta", "cut_points", cut_points)


    '''
    @note: write the feature_code
    '''
    f = open('./feature/feature_code.json', 'r')
    feature_code = json.load(f)
    f.close()

    feature_code = json.dumps(feature_code)
    # print(type(layer))
    client.hpush("feature_meta", "feature_code", feature_code)



    '''
    @note: write the feature_code
    '''
    f = open('./feature/feature_slot.json', 'r')
    feature_slot = json.load(f)
    f.close()

    feature_slot = json.dumps(feature_slot)
    # print(type(layer))
    client.hpush("feature_meta", "feature_slot", feature_slot)


    '''
    @note: write the feature_store, the information about the feature we deal and where we can get these features
    '''
    f = open('./feature/feature_store.json', 'r')
    feature_store = json.load(f)
    f.close()

    feature_store = json.dumps(feature_store)
    # print(type(layer))
    client.hpush("feature_meta", "feature_store", feature_store)



    '''
    @note: write the redis_map, the information about the redis where we store the features
    '''
    f = open('./feature/redis_map.json', 'r')
    redis_map = json.load(f)
    # print(redis_map)
    f.close()

    redis_map = json.dumps(redis_map)
    # print(type(layer))
    client.hpush("feature_meta", "redis_map", redis_map)
        
    '''
    @note: write the fea_code_map, the fea_name, code and the value tap map.
    '''    
    f = open('./feature/fea_code_map.json', 'r')
    fea_code_map = json.load(f)
    fea_code_map = json.dumps(fea_code_map)
    client.hpush('feature_meta', 'fea_code_map', fea_code_map)

    


    transport.close()
except thrift.TException as ex:
    print(ex.message)